package com.example.demo;

import lombok.Data;

/**
 * @author lk
 */
@Data
public class ResultData<T> {
    //200:成功
    public String code;
    public String msg;
    public T data;

    private ResultData(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResultData success() {
        return new ResultData("200", "SUCCESS", null);
    }

    public static ResultData success(String data) {
        return new ResultData("200", "SUCCESS", data);
    }

    public static <T> ResultData<T> success(T data) {
        return new ResultData<>("200", "SUCCESS", data);
    }

    public static <T> ResultData<T> error() {
        return new ResultData("201", "FAILURE", null);
    }

    public static <T> ResultData<T> error(String message) {
        return new ResultData("201", message, null);
    }

    public static <T> ResultData<T> error(String code, String message) {
        return new ResultData(code, message, null);
    }
}
